/* rqwrthst.p - REQUISITION WRITE HISTORY RECORD                              */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/*V8:ConvertMode=NoConvert                                                    */
/* Revision: 8.5      LAST MODIFIED: 04/22/97   By: B. Gates        *J1Q2*    */
/* REVISION: 8.6E     LAST MODIFIED: 06/01/00   BY: *L0YQ* Mark Christian     */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */


         {mfdeclre.i}


         /*GPRUN.I TEMPLATE:
         {gprun.i ""rqwrthst.p""
     "(input p_nbr,
     input p_line,
     input p_action,
     input p_apr_userid,
     input p_rtto_userid,
     input p_email_list)"}
         */


         define input parameter p_nbr like rqh_nbr no-undo.
         define input parameter p_line like rqh_line no-undo.
         define input parameter p_action like rqh_action no-undo.
         define input parameter p_apr_userid like rqh_apr_userid no-undo.
         define input parameter p_rtto_userid like rqh_rtto_userid no-undo.
         define input parameter p_email_list like rqh_email_list no-undo.

     define variable assign_ok as logical no-undo.
     define variable seq as integer no-undo.
     define variable todays_date as date no-undo.
     define variable time_of_day as integer no-undo.



     todays_date = today.
     time_of_day = time.

/*L0YQ** BEGIN DELETE
 *       find last rqh_hist
 *       where rqh_nbr = rqh_nbr
 *       and rqh_date = todays_date
 *       and rqh_time = time_of_day
 *       no-lock no-error.
 *L0YQ** END DELETE */

/*L0YQ*/ for last rqh_hist
/*L0YQ*/    fields (rqh_action rqh_apr_userid rqh_date rqh_email_list
/*L0YQ*/            rqh_ent_userid rqh_line rqh_nbr rqh_rtto_userid
/*L0YQ*/            rqh_seq_nbr rqh_time)
/*L0YQ*/    where rqh_nbr  = p_nbr
/*L0YQ*/      and rqh_date = todays_date
/*L0YQ*/      and rqh_time = time_of_day
/*L0YQ*/      no-lock:
/*L0YQ*/ end. /* FOR LAST RQH_HIST */

         if available rqh_hist then seq = rqh_seq_nbr + 1.

     create rqh_hist.

     assign
         rqh_nbr = p_nbr
         rqh_line = p_line
         rqh_action = p_action
         rqh_apr_userid = p_apr_userid
         rqh_ent_userid = global_userid
         rqh_rtto_userid = p_rtto_userid
         rqh_email_list = p_email_list
     rqh_seq_nbr = ?
     rqh_date = todays_date
     rqh_time = time_of_day
     .

     if recid(rqh_hist) = -1 then.


     do while not assign_ok:
        do on error undo, leave.
               rqh_seq_nbr = seq.
           assign_ok = true.
        end.

            seq = seq + 1.
     end.
